/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * frmInscribir.java
 *
 * Created on 17/02/2011, 10:08:26 AM
 */
package Principal;

import Clases.Estudiante;
import Clases.Seccion;
import java.awt.Frame;
import javax.swing.JOptionPane;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class frmInscribir extends javax.swing.JFrame {

	/** Creates new form frmInscribir */
	public frmInscribir() {
		initComponents();
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		jScrollPane1 = new javax.swing.JScrollPane();
		jTable1 = new javax.swing.JTable();
		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		jLabel3 = new javax.swing.JLabel();
		jLabel4 = new javax.swing.JLabel();
		txtCedula = new javax.swing.JTextField();
		txtNombre = new javax.swing.JTextField();
		txtApellido = new javax.swing.JTextField();
		bInscribir = new javax.swing.JButton();
		bCancelar = new javax.swing.JButton();
		bSalir = new javax.swing.JButton();
		bRetirar = new javax.swing.JButton();
		bBuscar = new javax.swing.JButton();

		jTable1.setModel(new javax.swing.table.DefaultTableModel(
				new Object[][] { { null, null, null, null },
						{ null, null, null, null }, { null, null, null, null },
						{ null, null, null, null } }, new String[] { "Title 1",
						"Title 2", "Title 3", "Title 4" }));
		jScrollPane1.setViewportView(jTable1);

		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		jLabel1.setText("Registro de Alumnos");

		jLabel2.setText("Nombre:");

		jLabel3.setText("Apellido:");

		jLabel4.setText("Cédula:");

		txtCedula.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				txtCedulaActionPerformed(evt);
			}
		});

		txtApellido.setText(" ");

		bInscribir.setText("Inscribir");
		bInscribir.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bInscribirActionPerformed(evt);
			}
		});

		bCancelar.setText("Cancelar");
		bCancelar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bCancelarActionPerformed(evt);
			}
		});

		bSalir.setText("Salir");
		bSalir.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bSalirActionPerformed(evt);
			}
		});

		bRetirar.setText("Retirar");
		bRetirar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bRetirarActionPerformed(evt);
			}
		});

		bBuscar.setText("Buscar");
		bBuscar.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				bBuscarActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGap(100,
																		100,
																		100)
																.addComponent(
																		jLabel1,
																		javax.swing.GroupLayout.PREFERRED_SIZE,
																		202,
																		javax.swing.GroupLayout.PREFERRED_SIZE))
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(38,
																										38,
																										38)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING)
																												.addComponent(
																														jLabel2)
																												.addComponent(
																														jLabel3)
																												.addComponent(
																														jLabel4,
																														javax.swing.GroupLayout.Alignment.LEADING)))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(54,
																										54,
																										54)
																								.addComponent(
																										bInscribir)))
																.addPreferredGap(
																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addComponent(
																										bCancelar)
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(
																										bRetirar)
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(
																										bSalir))
																				.addGroup(
																						layout.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																								.addComponent(
																										txtNombre,
																										javax.swing.GroupLayout.DEFAULT_SIZE,
																										105,
																										Short.MAX_VALUE)
																								.addGroup(
																										layout.createSequentialGroup()
																												.addComponent(
																														txtCedula,
																														javax.swing.GroupLayout.PREFERRED_SIZE,
																														83,
																														javax.swing.GroupLayout.PREFERRED_SIZE)
																												.addGap(18,
																														18,
																														18)
																												.addComponent(
																														bBuscar))
																								.addComponent(
																										txtApellido)))))
								.addContainerGap(64, Short.MAX_VALUE)));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGap(29, 29, 29)
								.addComponent(jLabel1)
								.addGap(39, 39, 39)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel4)
												.addComponent(
														txtCedula,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE)
												.addComponent(bBuscar))
								.addGap(30, 30, 30)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel2)
												.addComponent(
														txtNombre,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(26, 26, 26)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel3)
												.addComponent(
														txtApellido,
														javax.swing.GroupLayout.PREFERRED_SIZE,
														javax.swing.GroupLayout.DEFAULT_SIZE,
														javax.swing.GroupLayout.PREFERRED_SIZE))
								.addGap(39, 39, 39)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(bInscribir)
												.addComponent(bCancelar)
												.addComponent(bRetirar)
												.addComponent(bSalir))
								.addContainerGap(37, Short.MAX_VALUE)));

		java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit()
				.getScreenSize();
		this.setBounds(0, 0, 423, 329);
	}// </editor-fold>//GEN-END:initComponents

	private void txtCedulaActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_txtCedulaActionPerformed
		// TODO add your handling code here:
	}// GEN-LAST:event_txtCedulaActionPerformed

	private void bSalirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bSalirActionPerformed
		// TODO add your handling code here:
		dispose();
	}// GEN-LAST:event_bSalirActionPerformed

	private void bInscribirActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bInscribirActionPerformed
		// TODO add your handling code here:
		Estudiante estudiante;
		if (!txtCedula.getText().isEmpty() && !txtNombre.getText().isEmpty()
				&& !txtApellido.getText().isEmpty()) {
			estudiante = new Estudiante(txtNombre.getText(),
					txtApellido.getText(), txtCedula.getText());
			frmInicial.seccion.InscribirEstrudiante(estudiante);
			txtApellido.setText("");
			txtCedula.setText("");
			txtNombre.setText("");
		} else {
			JOptionPane.showMessageDialog(new Frame(),
					"Hay campos en blanco, por favor verifique");
		}
	}// GEN-LAST:event_bInscribirActionPerformed

	private void bBuscarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bBuscarActionPerformed
		// TODO add your handling code here:
		int existe = 0;
		if (!txtCedula.getText().equals("")) {
			txtNombre.setText("");
			txtApellido.setText("");
			existe = frmInicial.seccion.BuscarEstudiante(txtCedula.getText());
			System.out.println(existe);
			if (existe >= 0) {
				txtNombre.setText(frmInicial.seccion.getEstudiantes()
						.elementAt(existe).getNombre());
				txtApellido.setText(frmInicial.seccion.getEstudiantes()
						.elementAt(existe).getApellido());
			}
		} else {
			JOptionPane.showMessageDialog(new Frame(), "Introduzca una cedula");
		}
	}// GEN-LAST:event_bBuscarActionPerformed

	private void bCancelarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bCancelarActionPerformed
		// TODO add your handling code here:
		txtApellido.setText("");
		txtCedula.setText("");
		txtNombre.setText("");
	}// GEN-LAST:event_bCancelarActionPerformed

	private void bRetirarActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_bRetirarActionPerformed
		// TODO add your handling code here:
		if (!txtCedula.getText().equals("")) {
			txtNombre.setText("");
			txtApellido.setText("");
			frmInicial.seccion.RetirarEstudiante(txtCedula.getText());
			txtCedula.setText("");
		} else {

			JOptionPane.showMessageDialog(new Frame(), "Introduzca una cedula");

		}

	}// GEN-LAST:event_bRetirarActionPerformed

	/**
	 * @param args
	 *            the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {

			public void run() {
				new frmInscribir().setVisible(true);
			}
		});
	}

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton bBuscar;
	private javax.swing.JButton bCancelar;
	private javax.swing.JButton bInscribir;
	private javax.swing.JButton bRetirar;
	private javax.swing.JButton bSalir;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JTable jTable1;
	private javax.swing.JTextField txtApellido;
	private javax.swing.JTextField txtCedula;
	private javax.swing.JTextField txtNombre;
	// End of variables declaration//GEN-END:variables
}
